<?php
namespace BP\Sys;

use EntityOID;

require_once("BP/En/Map.php");
require_once("BP/Web/WebUser.php");
class GEDtl extends EntityOID {
	public $FK_MapDtl;	// String
	private function __init() { // default class members
		$this->FK_MapDtl = NULL;
	}
	public function toString () 
	{
		return $this->FK_MapDtl;
	}
	public function getClassID () 
	{
		return $this->FK_MapDtl;
	}
	public function getRDT () 
	{
		return $this->GetValStringByKey(GEDtlAttr::$RDT);
	}
	public function setRDT ($value) // [String value]
	{
		$this->SetValByKey(GEDtlAttr::$RDT, $value);
	}
	public function getRec () 
	{
		return $this->GetValStringByKey(GEDtlAttr::$Rec);
	}
	public function setRec ($value) // [String value]
	{
		$this->SetValByKey(GEDtlAttr::$Rec, $value);
	}
	public function getRefPK () 
	{
		return $this->GetValStringByKey(GEDtlAttr::$RefPK);
	}
	public function setRefPK ($value) // [String value]
	{
		$this->SetValByKey(GEDtlAttr::$RefPK, $value);
	}
	public function getRefPKInt64 () 
	{
		return $this->GetValInt64ByKey(GEDtlAttr::$RefPK);
	}
	public function setRefPKInt64 ($value) // [long value]
	{
		$this->SetValByKey(GEDtlAttr::$RefPK, $value);
	}
	public function getIsRowLock () 
	{
		return $this->GetValBooleanByKey(GEDtlAttr::$IsRowLock);
	}
	public function setIsRowLock ($value) // [boolean value]
	{
		$this->SetValByKey(GEDtlAttr::$IsRowLock, $value);
	}
	public function getRefPKInt () 
	{
		return $this->GetValIntByKey(GEDtlAttr::$RefPK);
	}
	public function setRefPKInt ($value) // [int value]
	{
		$this->SetValByKey(GEDtlAttr::$RefPK, $value);
	}
	public function getFID () 
	{
		return $this->GetValInt64ByKey(GEDtlAttr::$FID);
	}
	public function setFID ($value) // [long value]
	{
		$this->SetValByKey(GEDtlAttr::$FID, $value);
	}
	public static function constructor__ () 
	{
		$me = new self();
		$me->__init();
		return $me;
	}
	public static function constructor__String ($fk_mapdtl) // [String fk_mapdtl]
	{
		$me = new self();
		$me->__init();
		$me->FK_MapDtl = $fk_mapdtl;
		return $me;
	}
	public static function constructor__String_I ($fk_mapdtl, $_oid) // [String fk_mapdtl, int _oid]
	{
		$me = new self();
		$me->__init();
		$me->FK_MapDtl = $fk_mapdtl;
		$me->setOID($_oid);
		return $me;
	}
	public function getEnMap () 
	{
		if (($this->get_enMap() != NULL))
		{
			return $this->get_enMap();
		}
		if (($this->FK_MapDtl == NULL))
		{
			throw new \RuntimeException((("没有�?" . $this->FK_MapDtl) . "值，您不能获取它的Map�?"));
		}
		$md = MapDtl::constructor__String($this->FK_MapDtl);
		$this->set_enMap($md->GenerMap());
		return $this->get_enMap();
	}
	public function getGetNewEntities () 
	{
		if (($this->FK_MapDtl == NULL))
		{
			return GEDtls::constructor__();
		}
		return GEDtls::constructor__String($this->FK_MapDtl);
	}
	public function IsChange ($dtl) // [GEDtl dtl]
	{
		$attrs = $dtl->getEnMap()->getAttrs();
		foreach ($attrs as $attr) 		{
			$oldVal = $this->GetValByKey($attr->getKey());
			$val = $dtl->GetValByKey($attr->getKey());
			if (($oldVal == NULL))
			{
				if (($oldVal != NULL))
					return  TRUE ;
			}
			else
			{
				if (($oldVal == NULL))
					return  TRUE ;
				if (($oldVal->equals($val) ==  TRUE ))
					continue;
				else
					return  TRUE ;
			}
		}
		return  FALSE ;
	}
	protected function beforeInsert () 
	{
		$mattrs = MapAttrs::constructor__String($this->FK_MapDtl);
		$isChange =  FALSE ;
		foreach ($mattrs->ToJavaList() as $mattr) 		{
			if ($isChange)
			{
				break;
			}
			switch ($mattr->getKeyOfEn()) {
				case "Rec":
				case "RDT":
				case "FID":
					break;
				default:
					if ($mattr->getIsNum())
					{
						$s = $this->GetValStrByKey($mattr->getKeyOfEn());
						if ($DataType->IsNullOrEmpty($s))
						{
							$this->SetValByKey($mattr->getKeyOfEn(), $mattr->getDefVal());
							$s = $mattr->getDefVal();
						}
						$s = $s->replace("�?", "");
						$s = $s->replace(",", "");
						if ($mattr->getDefValDecimal()->equals($BigDecimal->valueOf($Double->parseDouble(($s)))))
						{
							continue;
						}
						$isChange =  TRUE ;
						break;
					}
					else
					{
						if ($this->GetValStrByKey($mattr->getKeyOfEn())->equals($mattr->getDefVal()))
						{
							continue;
						}
						$isChange =  TRUE ;
						break;
					}
			}
		}
		if (($isChange ==  FALSE ))
		{
			return  FALSE ;
		}
		$this->setRec($WebUser->getNo());
		$this->setRDT($DataType->getCurrentDataTime());
		return parent->beforeInsert();
	}
}
?>
